package com.example.carport.service.Impl;

import com.example.carport.dao.CarportMapper;
import com.example.carport.service.CarportService;
import com.example.entity.Carport;
import com.example.result.CommonResult;
import com.example.utils.MyOSSUtil;
import com.example.utils.MyPageHelper;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Service
public class CarportServiceImpl implements CarportService {
    @Autowired
    CarportMapper carportMapper;

    @Autowired
    RabbitTemplate rabbitTemplate;
    /**
     * 停车场管理-车位全查
     * @param carportCustomerBinding
     * @return
     */
    @Override
    public CommonResult getCarport(String carportCustomerBinding) {
        return CommonResult.ok(MyPageHelper.getPageResult(carportMapper.getCarport(carportCustomerBinding)));
    }

    /**
     * 停车场管理-车位删除
     * @param id
     * @return
     */
    @Override
    public int delCarport(Integer id) {
        int i = carportMapper.delCarport(id);
        return i;
    }

    /**
     * 停车场管理-车位增改
     * @param carport
     * @return
     */
    @Override
    public int saveOrUpdateCarport(MultipartFile file, Carport carport) {
            if (file!=null){
            final MyOSSUtil myOSSUtil = new MyOSSUtil();
            final String s = myOSSUtil.uploadFile(file);
            carport.setFileId(s);
        }else{
            carport.setFileId("null");
        }
        int i = 0;
        if(carport.getId() == 0){
            carport.setCarportDelFlag(0);
            carport.setCarportCustomerBinding(1);
            i = carportMapper.addCarport(carport);
        }else {
            i = carportMapper.updateCarport(carport);
        }
        return i;
    }

    /**
     * 停车场管理-车位审批
      * @return
     */
    @Override
    public CommonResult getApprover() {
        return CommonResult.ok(MyPageHelper.getPageResult(carportMapper.getApprover()));
    }

    /**
     * 停车场管理-车位审批通过
     * @param id
     * @return
     */
    @Override
    public int passApprover(Integer id) {
        int i = carportMapper.passApprover(id);
        return i;
    }

    /**
     * 停车场管理-车位驳回
     * @param id
     * @return
     */
    @Override
    public int rejectApprover(Integer id) {
        int i = carportMapper.rejectApprover(id);
        return i;
    }
    /**
     * 车辆管理-车位审批通过
     */
    @Override
    public CommonResult getPassApprover() {
        return CommonResult.ok(MyPageHelper.getPageResult(carportMapper.getPassApprover()));
    }
    /**
     * 车辆管理-车位未审批通过
     */
    @Override
    public CommonResult getRejectApprover() {
        return CommonResult.ok(MyPageHelper.getPageResult(carportMapper.getRejectApprover()));
    }
}
